#include "ros/ros.h"
#include "std_msgs/String.h"
#include "package1/crypto.h"
#include "package1/Num.h"
static std::string _the_key;
static unsigned int _the_key_size;
void my_Callback(const package1::Num::ConstPtr & msg)
{    
    if(msg->the_key == _the_key)
    {
        std::string de_base64 = CCryptoUtil::aes_decrypt_ecb_hex(msg->Data.data, (unsigned char*)msg->the_key.c_str(), _the_key_size);
        ROS_INFO("I HEARD [%s]",de_base64.c_str());
    }else{
        ROS_ERROR(" BAD CODE ");
    }
    
    // int iResult = CCryptoUtil::decrypt4aes(msg->strResult,msg->strKey,strPlainText,strerrmsg);
    // param分别是 AES加密的结果、密钥、接受AES解密结果的string对象、接受报错信息的string对象；
    
}

int main(int argc ,char** argv)
{
	ros::init(argc,argv,"listener1");
    ros::NodeHandle nh;
    std::cout << "Input your key:";
    std::cin>>_the_key;
    _the_key_size = _the_key.size();
    ros::Subscriber listener1 = nh.subscribe("/chatter",10000,my_Callback);
    ros::spin();
    
    return 0;
}



